<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我的收藏</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/member.css"/>
    <script type="text/javascript" src="../../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../../script/mobile.js"></script>
    <script type="text/javascript">
        window['adaptive'].desinWidth = 750;
        window['adaptive'].baseFont = 28;
        window['adaptive'].maxWidth = 750;
        window['adaptive'].init();
    </script>
</head>

<body>
<div id="header" style="height: 0.9rem; background: #fff; position: fixed; top: 0;left: 0; width: 100%; z-index: 99">
    <header class="header header-shadow" id="doubleClick">
        <div class="header-left">
            <div tapmode onclick="comeBack();" class="nav-left"><img class="icon-back" src="../../icon/icon-back.png"/>
            </div>
        </div>
        <h2>浏览记录</h2>
        <div class="header-right">
            <div tapmode onclick="clearRecode();" class="nav-right c-999">清空</div>
        </div>
    </header>
</div>
<div class="mescroll" id="mescroll" style="padding-top: 1.5rem">
    <section class="html_section pr30 pl30 ">
        <div class="activity-list collection-list">
            <ul>
                <!--<li class="list-li" onclick="commonUrl()" tapmode >
                   <div class="flex-div">
                       <div class="act-info">
                           <div class="collection-title multiline-ellipsis_3 f28 c-333">历史的今天，苹果发生了一件意义重大的【事件】，在当时也是引起了很大轰动。</div>
                           <div class="detail-bottom">
                               <div class="bottom-tips">
                                   <span class="bt-pd tips">#读书会#</span>
                                   <span class="bt-pd time">15分钟前</span>

                               </div>
                               <div class="bottom-hot">3.3w</div>
                           </div>
                       </div>
                       <div class="act-img bg-cover" style="background-image: url('../../image/img-activity.png')"></div>
                   </div>
               </li>-->
            </ul>
            <div class="nodata"></div>
        </div>
    </section>
</div>

</body>
</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<link rel="stylesheet" type="text/css" href="../../css/mescroll.min.css"/>
<script type="text/javascript" src="../../script/mescroll.min.js"></script>
<script type="text/javascript">
    var page = 1;
    var ifpage = true;
    apiready = function () {
        setFixStatusBar(); //设置状态栏
        pop.loading();
        keybackListener()

        //上拉加载
        /*pullUpLoading(function () {
            if (ifpage) {
                page++;
                ready();
            }
        });*/
        //下拉刷新
        /*dropDownRefresh(function () {
            page = 1
            ready();
        })*/
        var isOne = true;
        api.addEventListener({
            name: 'viewappear'
        }, function (ret, err) {
            if (isOne) {
                isOne = false;
                ready();
            }
        });
    }

    //创建MeScroll对象
    var mescroll = new MeScroll("mescroll", {
        down: {
            auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true
            callback: downCallback //下拉刷新的回调
        },
        up: {
            auto: false, //是否在初始化时以上拉加载的方式自动加载第一页数据; 默认false
            isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10
            callback: upCallback, //上拉回调,此处可简写; 相当于 callback: function (page) { upCallback(page); }
            /*toTop:{ //配置回到顶部按钮
                src : "../res/img/mescroll-totop.png", //默认滚动到1000px显示,可配置offset修改
                //offset : 1000
            }*/
        }
    });
    /*下拉刷新的回调 */
    function downCallback() {
        page = 1
        ready();

        //mescroll.endErr();
    }
    /*上拉加载的回调 */
    function upCallback() {
        if (ifpage == true) {
            page++;
            ready();
        }else {
            mescroll.endErr();
        }
    }

    function ready() {
        getAjax(Interface.get_browse, {token: $api.getStorage('token'), page: page}, function (res) {
            pop.close();
            var list = res.data.list;
            if(isDefine(list)){
                var html = '';
                $.each(list, function (i, item) {
                    var data = item.data;
                    if(isDefine(data)){
                        var result = getDataType(item);
                        html += '<li class="list-li">';
                            html += '<div class="flex-div">';
                                html += '<div class="act-info">';
                                    html += '<div class="collection-title multiline-ellipsis f28 c-333" onclick=\'commonUrl("' + result.url + '",' + jsonChange(result.urlParam) + ')\' tapmode >' + data.title + '</div>';
                                    html += '<div class="detail-bottom">';
                                        html += '<div class="bottom-tips">';
                                            if (isDefine(data.news_label_name)){
                                                html += '<span class="bt-pd tips">#' + data.news_label_name[0].title + '#</span>';
                                            }else if(isDefine(data.circle_title)){
                                                html += '<span class="bt-pd tips">#' + data.circle_title + '#</span>';
                                            }

                                            html += '<span class="bt-pd time">' + data.date + '</span>';
                                        html += '</div>';
                                        html += '<div class="bottom-hot">' + data.hot_number + '</div>';
                                    html += '</div>';
                                html += '</div>';
                            if (isDefine(data.void_icon_path)){
                                html += '<div class="act-img bg-cover"  onclick=\'commonUrl("' + result.url + '",' + jsonChange(result.urlParam) + ')\' tapmode  style="background-image: url(' + getImg(data.void_icon_path) + ')"></div>';
                            }else if(isDefine(data.icons_path)){
                                html += '<div class="act-img bg-cover"  onclick=\'commonUrl("' + result.url + '",' + jsonChange(result.urlParam) + ')\' tapmode  style="background-image: url(' + getImg(data.icons_path[0]) + ')"></div>';
                            }else if(isDefine(data.icon_path)){
                                html += '<div class="act-img bg-cover"  onclick=\'commonUrl("' + result.url + '",' + jsonChange(result.urlParam) + ')\' tapmode  style="background-image: url(' + getImg(data.icon_path[0]) + ')"></div>';
                            }else{
                                html += '<div class="act-img bg-cover"  onclick=\'commonUrl("' + result.url + '",' + jsonChange(result.urlParam) + ')\' tapmode  style="background-image: url(../../icon/logo.png)"></div>';
                            }

                            html += '</div>';
                        html += '</li>';
                    }

                })

            }
            pop.close();
            if (page == 1) {
                console.log(html)
                $(".collection-list ul").html(html);
            } else {
                $(".collection-list ul").append(html);
            }


            if (list.length < res.data.sumpage) {
                ifpage = false;
                $(".nodata").show();
            } else {
                $(".nodata").hide();
            }
            if (list.length == 0) {
                if (page == 1) {
                    $(".nodata").hide();
                    $(".collection-list ul").html(noData);
                }
            }
            mescroll.endErr()
        }, function (res, err) {
            mescroll.endErr()
        })
    }


    function clearRecode() {
        confirmBox('清空浏览记录', '您确认要清空吗', function () {
            pop.loading();
            getAjax(Interface.browse_del, {token: $api.getStorage('token')}, function (res) {
                pop.close();
                $(".collection-list ul").empty();
                $(".nodata").show();
            }, function (res, err) {
            })
        })
    }

    function getDataType(item) {
        var result = '帖子';
        var url = '../circle/invite_detail';
        var urlParam = {'invitation_id': item.data.id};
        switch (item.leixing) {
            case 1:
                result = '新闻';
                url = '../index/news_detail';
                urlParam = {'news_id': item.data.id};
                break;
            case 2:
                result = '帖子';
                url = '../circle/invite_detail';
                urlParam = {'invitation_id': item.data.id};
                break;
            case 3:
                result = '活动';
                url = '../activity/activity_index';
                urlParam = {"activity_id": item.data.id};
                break;
        }
        return {
            text: result,
            url: url,
            urlParam: urlParam
        }
    }


</script>
